package com.ycy.controller.employee;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.ycy.pojo.Employee;
import com.ycy.pojo.Role;
import com.ycy.service.Role.RoleService;

@Controller
public class RoleController {

	@Autowired
	RoleService service;
	@RequestMapping("/role_list")
	public String roleList(HttpServletRequest request,Model m,HttpSession session){
		
		List<Role> rolers= service.findall();
		session.setAttribute("Rolers",rolers);
		return "role_list";
	}
	
	@RequestMapping("/role_del")
	public String roleDel(int id,HttpServletRequest request,Model m,HttpSession session){
		int n= service.del(id);
		if(n>0){
			return "ok";
		}else{
			return "fail";
		}
	}
	@RequestMapping("/role_add")
	public String roleAdd(){
		return "role_add";
	}
	@RequestMapping("/do_role_add")
	public String roleDoAdd(Role role,HttpSession session){
		int n= service.add(role);
		if(n>0){
			return "ok";
		}else{
			return "fail";
		}
	}
	@RequestMapping("/role_edit")
	public String roleEdit(HttpServletRequest request,Model m,HttpSession session){
		Employee employee= (Employee) session.getAttribute("Me");
		Role role=service.findByName(employee.getName());
		session.setAttribute("role", role);
		return "role_edit";
	}
	@RequestMapping("/do_role_edit")
	public String roleDoEdit(Role role,HttpSession session){
		int n= service.edit(role);
		if(n>0){
			return "ok";
		}else{
			return "fail";
		}
	}
	

}
